
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:include page="./common/header.jsp"/>

<style type="text/css">
    body{background: url(static/image/4.jpg) no-repeat;background-size: cover;font-size: 16px;}
    .form{background: rgba(255,255,255,0.2);width:400px;margin:100px auto;}
    #register_form{display: block;}
    .fa{display: inline-block;top: 27px;left: 6px;position: relative;color: #ccc;}
    input[type="text"],input[type="password"]{padding-left:26px;}
    .checkbox{padding-left:21px;}
</style>

<body>
<div class="container">

    <div class="form row">
        <form class="form-horizontal col-sm-offset-3 col-md-offset-3" id="register_form" action="/user/add" method="post">
            <h3 class="form-title">Login to your account</h3>
            <div class="col-sm-9 col-md-9">
                <div class="form-group">
                    <i class="fa fa-user fa-lg"></i>
                    <input class="form-control required" type="text" placeholder="Username" name="name" autofocus="autofocus"/>
                </div>
                <div class="form-group">
                    <i class="fa fa-lock fa-lg"></i>
                    <input class="form-control required" type="password" placeholder="Password" id="register_password" name="password"/>
                </div>
                <div class="form-group">
                    <i class="fa fa-check fa-lg"></i>
                    <input class="form-control required" type="password" placeholder="Re-type Your Password" name="rePassword"/>
                </div>
                <div class="form-group">
                    <input type="submit" class="btn btn-success pull-right" value="Sign Up "/>
                    <input type="submit" class="btn btn-info pull-left" id="back_btn" value="Back"/>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript"  >
    $().ready(function() {
        $("#register_form").validate({
            rules: {
                username: "required",
                password: {
                    required: true,
                    minlength: 6,
                    maxlength:16,
                },
                rePassword: {
                    equalTo: "#register_password"
                }
            },
            messages: {
                username: "请输入姓名",
                password: {
                    required: "请输入密码",
                    minlength: jQuery.format("密码不能小于{0}个字 符"),
                    maxlength: jQuery.format("密码不能大于{0}个字 符")
                },
                rpassword: {
                    equalTo: "两次密码不一样"
                }
            }
        });
        $('#register_form').submit(function () {
            $(this).ajaxSubmit({
                dataType: "json",
                success: function (data) {
                    if (data.code == '200') {
                        window.location.href = '/login';
                    } else {
                        $("#errdiv").css("display", "flex");
                        $("#message").html(data.message);
                    }
                },
                error: function () {
                    $("#errdiv").css("display", "flex");
                    $("#message").html("操作失败，请联系管理员");
                }
            });
            return false;
        });
    });
</script>
</body>
</html>

